package com.molichuxing.services.infrastructure.service.impl;

import com.molichuxing.services.infrastructure.bean.VehicleColorBean;
import com.molichuxing.services.infrastructure.convertor.Convert;
import com.molichuxing.services.infrastructure.dao.VehicleColorMapper;
import com.molichuxing.services.infrastructure.dto.response.VehicleColorDto;
import com.molichuxing.services.infrastructure.service.VehicleColorService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import javax.annotation.Resource;

/**
 * <p>
 * 车型颜色 服务实现类
 * </p>
 *
 * @author 
 * @since 2019-07-29
 */
@Service("vehicleColorService")
public class VehicleColorServiceImpl  implements VehicleColorService {

  @Resource
  private   VehicleColorMapper  vehicleColorMapper;

  @Override
  public VehicleColorDto getVehicleColorByvehicleColorId(Integer vehicleColorId) {
    //根据颜色id 查询颜色
    VehicleColorBean vehicleColorBean = vehicleColorMapper.getById(vehicleColorId);
    return Convert.toVehicleColorBeanDto(vehicleColorBean);
  }

    @Override
    public VehicleColorDto getVehicleColorByvehicleColor(String vehicleColor) {
        VehicleColorBean vehicleColorBean = vehicleColorMapper.getByName(vehicleColor);
        return Convert.toVehicleColorBeanDto(vehicleColorBean);
    }

    @Override
  public Map<Integer, VehicleColorDto> getVehicleColors(List<Integer> vehicleColorIds) {
		if(null == vehicleColorIds || vehicleColorIds.isEmpty()) {
			return null;
		}
		
		List<VehicleColorBean> list =vehicleColorMapper.getByIds(vehicleColorIds);
		List<VehicleColorDto> vehicleColorBeanDtos = Convert.toVehicleColorBeanDto(list);
		if(null == vehicleColorBeanDtos || vehicleColorBeanDtos.isEmpty()) {
			return null;
		}
		
		Map<Integer, VehicleColorDto> map = vehicleColorBeanDtos.stream().collect(Collectors.toMap(VehicleColorDto::getId, a -> a,(k1, k2)->k1));
		return map;
  }

    @Override
    public VehicleColorDto getVehicleColorByVehicle(Integer vehicleId, String vehicleColor) {
        VehicleColorBean vehicleColorBean = vehicleColorMapper.getByNameAndVehicleId(vehicleId, vehicleColor);
        return Convert.toVehicleColorBeanDto(vehicleColorBean);
    }
}
